﻿package view.popup
{
    import com.core.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.geom.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import view.mornExtends.*;
    import vo.*;

    public class NewOpenlbUI extends View implements IDialogUI
    {
        public var btn_genghuan:Button;
        public var list:List;
        public var btn_close:Button;
        protected var uiXML:XML;
        private var _tools:Object;
        private var boxcfg:Object;
        private var itemsArr:Array;
        private var _data:Object;

        public function NewOpenlbUI()
        {
            this.uiXML = <View>r
n	t	t	t  <Image url=""png.common.cs2_tsbg"" width=""369"" height=""233"" sizeGrid=""10,50,10,50"" x=""1"" y=""1""/>r
n	t	t	t  <Image url=""jpg.common.neikuang"" x=""6"" y=""34""/>r
n	t	t	t  <Button label=""点击领取"" skin=""png.common.btn_cs2_bag"" x=""144"" y=""185"" labelStroke=""1"" labelFont=""SimSun"" labelColors=""0xb29a6c,0xb29a6c,0xfff7af"" var=""btn_genghuan""/>r
n	t	t	t  <List x=""40"" y=""54"" var=""list"" repeatX=""5"" spaceY=""6"" spaceX=""5"" repeatY=""2"">r
n	t	t	t	t<FlashItem name=""render"">r
n	t	t	t	t  <Image url=""png.common.img_1""/>r
n	t	t	t	t  <Image url=""png.common.noramlicon"" x=""5"" y=""5"" width=""47"" height=""46"" name=""icon""/>r
n	t	t	t	t  <Label text=""0"" x=""20"" y=""36"" color=""0xffe4c7"" font=""SimSun"" stroke=""1"" width=""33"" height=""18"" align=""right"" name=""count""/>r
n	t	t	t	t</FlashItem>r
n	t	t	t  </List>r
n	t	t	t  <Button skin=""png.common.btn_cs2_close"" x=""340"" y=""6"" var=""btn_close""/>r
n	t	t	t  <Label text=""开启宝箱获得物品"" x=""30"" y=""8"" width=""310"" height=""21"" color=""0xffe4c7"" bold=""true"" font=""SimSun"" stroke=""1"" size=""15"" align=""center""/>r
n	t	t	t</View>")("<View>
			  <Image url="png.common.cs2_tsbg" width="369" height="233" sizeGrid="10,50,10,50" x="1" y="1"/>
			  <Image url="jpg.common.neikuang" x="6" y="34"/>
			  <Button label="点击领取" skin="png.common.btn_cs2_bag" x="144" y="185" labelStroke="1" labelFont="SimSun" labelColors="0xb29a6c,0xb29a6c,0xfff7af" var="btn_genghuan"/>
			  <List x="40" y="54" var="list" repeatX="5" spaceY="6" spaceX="5" repeatY="2">
				<FlashItem name="render">
				  <Image url="png.common.img_1"/>
				  <Image url="png.common.noramlicon" x="5" y="5" width="47" height="46" name="icon"/>
				  <Label text="0" x="20" y="36" color="0xffe4c7" font="SimSun" stroke="1" width="33" height="18" align="right" name="count"/>
				</FlashItem>
			  </List>
			  <Button skin="png.common.btn_cs2_close" x="340" y="6" var="btn_close"/>
			  <Label text="开启宝箱获得物品\" x="30" y="8" width="310" height="21" color="0xffe4c7" bold="true" font="SimSun" stroke="1" size="15" align="center"/>
			</View>;
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            addEventListener(MouseEvent.MOUSE_DOWN, this.mouseDownHandler);
            return;
        }// end function

        private function mouseDownHandler(event:MouseEvent) : void
        {
            if (event.stageY < y + 30)
            {
                if (stage)
                {
                    stage.addEventListener(MouseEvent.MOUSE_MOVE, this.mouseMoveHandler);
                    stage.addEventListener(MouseEvent.MOUSE_UP, this.mouseUpHandler);
                }
            }
            return;
        }// end function

        private function mouseMoveHandler(event:MouseEvent) : void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, this.mouseMoveHandler);
            startDrag(false, new Rectangle(0, 0, stage.stageWidth - width, stage.stageHeight - height));
            return;
        }// end function

        private function mouseUpHandler(event:MouseEvent) : void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, this.mouseMoveHandler);
            stage.removeEventListener(MouseEvent.MOUSE_UP, this.mouseUpHandler);
            stopDrag();
            var _loc_2:* = this.btn_genghuan.localToGlobal(new Point(0, 0));
            ModelProxy.change("data", "itempoint", _loc_2);
            return;
        }// end function

        public function init() : void
        {
            this.visible = false;
            this.btn_genghuan.addEventListener(MouseEvent.CLICK, this.onSure);
            this.btn_close.addEventListener(MouseEvent.CLICK, this.onClose);
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width - 20;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height - 100;
            TweenVisibleManager.instance.register(this, TweenVisibleManager.Up, TweenVisibleManager.Auto);
            GlobalLayer.instance.root.stage.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function onSure(event:MouseEvent) : void
        {
            var _loc_2:Point = null;
            ModelProxy.change("plugin", "openBox", this._data);
            switch(this._data[0])
            {
                case 207595:
                case 207596:
                case 207597:
                case 207598:
                case 207599:
                case 207600:
                case 207601:
                case 207609:
                {
                    _loc_2 = this.btn_genghuan.localToGlobal(new Point(0, 0));
                    UIGlobel.pointsDic["tejie"] = _loc_2;
                    ModelProxy.change("mainui", "togetTejie", null);
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            this.close();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_9:String = null;
            var _loc_10:Array = null;
            var _loc_11:int = 0;
            var _loc_12:Array = null;
            var _loc_13:Object = null;
            this._data = param1;
            if (this.boxcfg == null)
            {
                this.boxcfg = ConfigDictionary.data.box;
            }
            if (this._tools == null)
            {
                this._tools = ConfigDictionary.data.item;
            }
            var _loc_2:* = param1[4].itemid;
            var _loc_3:* = this.boxcfg[_loc_2];
            if (!_loc_3)
            {
                return;
            }
            TweenVisibleManager.instance.changevisible(this, true);
            this.itemsArr = [];
            var _loc_4:* = UserData.getUserData("career");
            var _loc_5:* = UserData.getUserData("sex");
            var _loc_6:* = (_loc_3.items as String).split(";");
            var _loc_7:int = 0;
            while (_loc_7 < _loc_6.length)
            {
                
                _loc_9 = _loc_6[_loc_7];
                _loc_10 = _loc_9.split("#");
                _loc_11 = 0;
                while (_loc_11 < _loc_10.length)
                {
                    
                    _loc_9 = _loc_10[_loc_11];
                    _loc_12 = _loc_9.split("-");
                    if (_loc_12[0] == 0)
                    {
                    }
                    else if (_loc_12.length >= 5 && _loc_12[4] > 0 && _loc_12[4] != _loc_4)
                    {
                    }
                    else if (_loc_12.length >= 4 && _loc_12[3] != 2 && _loc_12[3] != _loc_5)
                    {
                    }
                    else
                    {
                        _loc_13 = ItemObject.create(this._tools[_loc_12[0]]);
                        _loc_13.count = int(_loc_12[1]);
                        this.itemsArr.push(_loc_13);
                    }
                    _loc_11++;
                }
                _loc_7++;
            }
            this.list.array = this.itemsArr;
            this.list.renderHandler = new Handler(this.listRender);
            var _loc_8:* = this.btn_genghuan.localToGlobal(new Point(0, 0));
            ModelProxy.change("data", "itempoint", _loc_8);
            return;
        }// end function

        private function listRender(param1:Component, param2:int) : void
        {
            if (param2 < this.list.length)
            {
                (param1 as FlashItem).data = this.list.array[param2];
            }
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            TweenVisibleManager.instance.changevisible(this, false);
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width - 20;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height - 100;
            TweenVisibleManager.instance.register(this, TweenVisibleManager.Up, TweenVisibleManager.Auto);
            var _loc_2:* = this.btn_genghuan.localToGlobal(new Point(0, 0));
            ModelProxy.change("data", "itempoint", _loc_2);
            return;
        }// end function

    }
}
